{
  // Cannot access 't1' before initialization
  //console.log(t1)
  console.log(t2)
  let t1 = 'haha'
  var t2 ='jj'
  //Identifier 't1' has already been declared
  //let t1 = 'kk'
}
//console.log(t1)
//ReferenceError: t1 is not defined
//console.log(t2)


//let属于会计作用域，var属于全局作用域
//可见var声明的是全局变量，在全局中存在的，setTimeout()是宏任务，执行完for再执行
for(var i =1;i<4;i++){
  setTimeout(()=>{
    console.log("var---"+i)
  },1000)
}
console.log("var---for循环以后再访问i----"+i)
//let 声明的是块级作用域
for(let i =1;i<4;i++){
  setTimeout(()=>{
    console.log("let----"+i)
  },1000)
}

var funcs = []; 
for (let i = 0; i < 10; i++) {
   funcs.push(function() { console.log("func-----i======",i); });
}
funcs.forEach(function(func) { func(); // 输出数值 "10" 十次 
});


//const声明的是常量
const t3 = {name:'xiaoming',age:19}
console.log(t3)
//{ name: 'xiaoming', age: 19 }
t3.name = 'mingming'
console.log(t3)
//{ name: 'mingming', age: 19 }
//t3={adress:'kk',sex:'man'}
//console.log(t3)
// Assignment to constant variable.
t4 = ['gg','dsdsd','home']
t4.push('key')
console.log(t4)
//[ 'gg', 'dsdsd', 'home', 'key' ]
